package cn.zcf.system.controller;

import cn.zcf.basic.utils.PageList;
import cn.zcf.system.annotation.PreAuthorize;
import cn.zcf.system.domain.Permission;
import cn.zcf.system.query.PermissionQuery;
import cn.zcf.system.service.IPermissionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private IPermissionService service;
    @GetMapping
    @ApiOperation(value = "查询全部" )

    public List<Permission> loadAll(){
        return service.loadAll();
    }
    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询" )
    public Permission loadById(@PathVariable("id") Long id){
        return service.loadById(id);
    }


    @PostMapping
    @ApiOperation(value = "分页查询" )
    @PreAuthorize(name = "权限列表",sn = "permission:list") //value后面用来做权限校验
    public PageList<Permission> pageQuery(@RequestBody PermissionQuery query){
        try {
            return service.pageQuery(query);
        } catch (Exception e) {
            e.printStackTrace();
            return new PageList<Permission>();
        }

    }

}
